/**
 * JAVACC DEMO 1.0
 */
package com.apache.uct.common;

import com.apache.action.ActionSupport;
import com.apache.api.entity.BaseEntity;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultMsg;
import com.apache.cache.util.Validator;
import com.apache.uct.common.entity.User;

import javax.servlet.http.HttpServletRequest;

/**
 * description:  Action父类
 *
 * @param <T>
 */
public abstract class BaseAction<T extends BaseEntity> extends ActionSupport<T> {

    protected User getSessionUser(HttpServletRequest request) {
        LoginUser loginUser = PBOSSOTools.getLoginUser(request);
        if (!Validator.isEmpty(loginUser)) {
            return loginUser.getUser();
        }
        return null;
    }

    protected String getSysFlag(HttpServletRequest request) {
        return Validator
                .getDefaultStr(String.valueOf(request.getSession().getAttribute("sysUser")), "0");
    }

    protected ResultMsg getResultMsg(HttpServletRequest request, String msg) {
        request.getSession().setAttribute("formToken", request.getAttribute("formToken"));
        ResultMsg rmsg = new ResultMsg("F", msg);
        return rmsg;
    }

    /**
     * description:  日志生成调用方法
     *
     * @param request
     */
    protected ParamsVo<T> getParamsVo(HttpServletRequest request) {
        ParamsVo<T> params = new ParamsVo<T>();
        params.setParams("logIp", getUserIp(request));
        params.setLogClassName(getGenType().trim());
        User user = getSessionUser(request);
        if (null == user)
            return params;
        params.setUserEname(user.getUserEname());
        params.setUserId(user.getUserId());
        return params;
    }

}
